#ifndef svl_TCommand_H
#define svl_TCommand_H

#include "svl_TPostMessage.h"

namespace svl {

//////////////////////////////////////////////////////////////////////////////
struct TCommand;
///////////////////////////////////////////////////////////////////////////////

struct TCommandArray : public TDebug
{
  void Clear() { a.Clear();}
  int  Count() { return a.Numb();}
  //
  void Add(TCommand *V,bool EnDelete = true);
  //
  TCommand &Get(int N);

private:
  TArray a;
};

///////////////////////////////////////////////////////////////////////////////

struct TCommand : public TArray_Object
{
  struct TPostExecute : public TPostMessage
  {
    TPostExecute(TCommand *Cmd,bool EnDeleteCmd = true) { cmd = Cmd; enDeleteCmd = EnDeleteCmd; Post();}
    virtual void TPostMessage_Receive()                 { cmd->Execute(); if (enDeleteCmd) { delete cmd;} }
  
  private:
    TCommand *cmd;
    bool enDeleteCmd;
  };
  //
  TString       Caption;
  
  TCommandArray Children;
  //
  TCommand()              { this->Caption = "???";}
  TCommand(char *Caption) { this->Caption = Caption;}
  //
  void Execute() { if (TCommand_GetEnable()) { TCommand_Execute();} }

//protected:
  virtual bool TCommand_GetEnable()  { return true;}
  virtual void TCommand_Execute() {}
};

//

struct TMenuCommand
{
  
  void Execute( int nItem ) { TMenuCommand_Execute( nItem ); }

//protected:
  virtual void TMenuCommand_Execute( int nItem ) =0;
};

///////////////////////////////////////////////////////////////////////////////
}

#endif
